var vm;

function hasPermission(permission) {
    var ispermission = '';
    $.ajaxSettings.async = false;
    $.get("../sys/role/hasPermission", {permission: permission}, function (r) {
        ispermission = r;
    });
    return ispermission;
}

function serializeObject(form) {
    var o = {};
    // form.find(".ui-select").each(function(r){
    //     var name=$(this).attr("name");
    //     var value=$(this).attr("data-value");
    //     o[name]= value;
    // })

    $.each(form.serializeArray(), function (index) {
        if (o[this['name']]) {
            o[this['name']] = o[this['name']] + "," + this['value'];
        } else {
            o[this['name']] = this['value'];
        }
    });
    return o;
}

(function ($) {
    $.fn.serializeJson = function () {
        var serializeObj = {};
        var array = this.serializeArray();
        var str = this.serialize();
        $(array).each(function () {
            if (serializeObj[this.name]) {
                if ($.isArray(serializeObj[this.name])) {
                    serializeObj[this.name].push(this.value);
                } else {
                    serializeObj[this.name] = [serializeObj[this.name], this.value];
                }
            } else {
                serializeObj[this.name] = this.value;
            }
        });
        return serializeObj;
    };
})(jQuery);

$(function () {

    vm = new Vue({
        el: '#rrapp',
        data: {
            startDate: "",
            endDate: "",
            idno: "",
            mobile: "",
            showList: true,
            title: null
        },
        methods: {
            query: function () {
                vm.reload();
            },
            reset: function () {
                // 送出後
                vm.startDate = "";
                vm.endDate = "";
                vm.idno = "";
                vm.mobile = "";
            },
            reload: function (event) {
                vm.showList = true;
                var page = $("#jqGrid").jqGrid('getGridParam', 'page');
                $("#jqGrid").setGridParam({
                    postData: {
                        startDate: vm.startDate,
                        endDate: vm.endDate,
                        idno: vm.idno,
                        mobile: vm.mobile
                    },
                    page: page
                }).trigger("reloadGrid");
            }
        }
    })

    $("#jqGrid").jqGrid({
        url: '../customer/list',
        datatype: "json",
        colModel: [
            {label: '客户ID', name: 'id', width: 40},
            {label: '手机号', name: 'mobile', width: 60},
            {label: '姓名', name: 'realName', width: 50},
            {label: '总资产（元）', name: 'totalAmount', width: 80},
            {label: '可用余额（元）', name: 'availableAmount', width: 80},
            {label: '冻结余额（元）', name: 'frozenAmount', width: 80},
            {label: '待收本金（元）', name: 'cashAmount', width: 80},
            {label: '操作', name: 'userCode', width: 100, formatter: formatFun}
        ],
        viewrecords: true,
        height: 400,
        rowNum: 10,
        rowList: [10, 30, 50],
        autowidth: true,
        multiselect: false,
        pager: "#jqGridPager",
        jsonReader: {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames: {
            page: "page",
            rows: "limit",
            order: "order"
        },
        gridComplete: function () {
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
        }
    });
});

function formatFun(cellvalue, options, rowObjec) {
    return '<p class="btn btn-success btn-xs" onclick="remark(\'' + cellvalue + '\')"><i class="fa fa-money"></i>&nbsp;查看详情</p> &nbsp;';
}

function remark(usercode) {
    sessionStorage.setItem("cusId",usercode);
    window.location.href="../homePage/viewDetail.html";
}




